﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Linn {
    public class ParameterCollection : ICollection<IParameter> {
        private List<IParameter> _parameters;

        public ParameterCollection() : this(4) { }

        public ParameterCollection(int capacity) {
            _parameters = new List<IParameter>(capacity);
        }

        public IParameter this[int index] {
            get { return _parameters[index]; }
        }

        public IParameter this[string name] {
            get {
                int index = _parameters.FindIndex(new Predicate<IParameter>(p => {
                    return p.Name == name;
                }));

                if (index > -1)
                    return _parameters[index];

                return null;
            }
        }

        public void Add(IParameter item) {
            _parameters.Add(item);
        }

        public void Clear() {
            _parameters.Clear();
        }

        public bool Contains(IParameter item) {
            return _parameters.Contains(item);
        }

        public void CopyTo(IParameter[] array, int arrayIndex) {
            _parameters.CopyTo(array, arrayIndex);
        }

        public int Count {
            get { return _parameters.Count; }
        }

        public bool IsReadOnly {
            get { return false; }
        }

        public bool Remove(IParameter item) {
            return _parameters.Remove(item);
        }

        public IEnumerator<IParameter> GetEnumerator() {
            return _parameters.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }
    }
}
